/* SVN FILE: $Id: application.js 12 2008-06-22 17:17:22Z rafaelbandeira3 $ */
/**
* Application : The Javascript MVC Framework
*
* @package application.core
* @subpackage cookie
* @author 			$Author: rafaelbandeira3 $
* @copyright 		(c) Rafael Bandeira, Marcelo Condotta, Henrique Condotta. All Rights Reserved.
* @version 			$Revision: 12 $
* @lastrevision 	$Date: 2008-06-22 17:17:22 +0000 (Sun, 22 Jun 2008) $
* @modifiedby 		$LastChangedBy: rafaelbandeira3 $
* @lastmodified 	$LastChangedDate: 2008-06-22 17:17:22 +0000 (Sun, 22 Jun 2008) $
* @license 			The MIT License [http://www.opensource.org/licenses/mit-license.php]
* @filesource 		$URL: http://jsmvcapplication.googlecode.com/svn/trunk/application/src/application.js $
*/
var time = (function()
{
	this.second = 1;
	this.minute = 60*this.second;
	this.hour 	= 60*this.minute;
	this.day 	= 24*this.hour;
	this.week 	= 7*this.day;
	this.month 	= 30*this.day;
	this.year 	= 365*this.day;
	
	return this;
})()

var $args = function(args)
{
	if(!(args instanceof Array))
		return new Array();

	if(args.length == 1)
		if(args[0] instanceof Array)
			args = args[0];
		else
			args = [arg[0]];
	return args;
}

var doc = document;
doc.__ready = false;
doc.onReady = function()
{
	args = $args(arguments);
	count = args.length;
	for(i=0;i<count;i++)
	{
		func = args[i];
		if(doc.__ready)
			func();
		else
			doc.observe('dom:loaded',func);
	}
}


/*
 * App namespace
 */
App = new Object(
{
	initialize : function()
	{
		element = $A(document.getElementsByTagName("script")).findAll(function(s)
			{return (s.src && s.src.match(/application\.js(\?.*)?$/))}).first();
		this.basePath = element.src.replace(/application\.js(\?.*)?$/,'');

		this.load('core');
	},
	load : function(type, args)
	{
		path = [this.basePath,type].join('')+'/';
		args = $args(args);

		if(args.length == 0)
			args = App.includes[type];
		
		count = args.length;
		for(i=0;i<count;i++)
			this.loadScript(path + args[i]);
	},
	loadScript : function(scriptPath)
	{
		if(scriptPath.indexOf('/') == -1)
			scriptPath = this.basePath + scriptPath;
		script = scriptPath+'.js';
		document.write('<script type="text/javascript" src="' + script + '"><\/script>');
	}
});
App.includes = new Object(
{
	'core' : $w('date string cookie xml')
});


App.initialize();
